<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-31 17:46:49
 * @LastEditTime : 2020-01-14 15:41:18
 * @LastEditors  : Please set LastEditors
 -->
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../../css/vant.css">
	<link rel="stylesheet" type="text/css" href="../../css/base.css" />
	<script type="text/javascript" src="../../script/jquery.js"></script>
	<script type="text/javascript" src="../../script/echarts.js"></script>
	<script type="text/javascript" src="../../script/layer/mobile/layer.js"></script>
	<script type="text/javascript" src="../../script/vue.min.js"></script>
	<script type="text/javascript" src="../../script/vant.min.js"></script>
	<script type="text/javascript" src="../../script/fastclick.js"></script>
	<script type="text/javascript" src="../../script/base.js"></script>
	<script type="text/javascript" src="../../script/formConfigReportToSelf.js"></script>
	<style type="text/css">
		.total {
			margin-top: 15px;
			background: #fff;
			text-align: center;
			margin-top: -1px;
		}

		.total-one {
			background: #cd1b21;
			text-align: center;
			margin-top: -1px;
		}

		.total .title {
			color: #9e9e9e;
			font-size: 13px;
		}

		.total .value {
			color: #000000;
			font-size: 22px;
			margin-bottom: 5px;
		}

		.total-one .title {
			color: rgba(255, 255, 255, .7);
			font-size: 13px;
		}

		.total-one .value {
			color: #ffffff;
			font-size: 22px;
			margin-bottom: 5px;
		}

		.van-grid-item__content {
			background-color: transparent;
		}

		.data {
			margin-top: 5px;
		}

		.data .row {
			margin-top: 5px;
		}

		.data .row .sort {
			display: inline-block;
			width: 20px;
			height: 20px;
			line-height: 20px;
			font-size: 12px;
			text-align: center;
			color: #fff;
			background: #cd1b21;
			border-radius: 4px;
			margin-right: 5px;
		}

		.data .row .sub {
			color: #9e9e9e;
			font-size: 12px;
		}

		.data .row .sub-bold {
			font-weight: 700;
			color: #000;
		}

		.required {
			color: #cd1b21;
			display: inline-block;
			width: 5px;
		}

		.hidden {
			visibility: hidden;
		}

		.no-data {
			text-align: center;
			color: #9e9e9e;
			line-height: 50px;
			font-size: 13px;
		}

		.full-height {
			height: 100% !important;
		}

		.row-button {
			position: fixed;
			left: 10px;
			right: 10px;
			z-index: 99999999;
			background: #fff;
			border-radius: 4px;
		}

		.row-button .arrow {
			position: absolute;
			width: 14px;
			right: 8px;
			top: -9px;

		}

		.van-cell__right-self {
			position: absolute;
			top: 0;
			right: 0;
			bottom: -10px;
			line-height: 48px !important;
			height: 44px;
			padding: 0 12px;
			margin: 0;
			width: 60px;
			text-align: right;
		}

		.row_bottom_button .van-cell__value {
			color: #1989fa;
		}


		.c {
			padding: 15px;
			width: 100%;
		}

		.c-t {
			padding: 0 16px 20px 16px;
			color: #9e9e9e;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="init-full">
			<van-nav-bar class="head" :title="objName" left-arrow @click-left="onClickLeft" v-if="!isFrame">
				<div slot="right" class="head-right">
					<span @click="showSearch = true;" v-show="getIsSearch()">
						<img src="../../image/search.png" />
					</span>
				</div>
			</van-nav-bar>
			<div :class="isSelect?'body-with-bottom':'body-no-bottom'">
				<div class="content">
					<van-list v-model="listLoading" :finished="listFinished" finished-text="没有更多了" @load="listOnLoad">


						<div :class="summaryData.length == 1?'total-one':'total'" v-show="summaryData.length">
							<van-grid :column-num="setTotalCol()" style="background: transparent;">
								<van-grid-item v-for="row in summaryData">
									<div>
										<div class="value">{{row.value}}</div>
										<div class="title">总{{row.label}}</div>
									</div>
								</van-grid-item>
							</van-grid>
						</div>
						<div class="data">
							<!-- <div class="no-data" v-show="!tableData_show.length">暂无数据</div> -->
							<div class="row" v-for="(row,index1) in tableData_show" @click="intoDetail(row,0)">
								<van-cell :is-link="getIsLink(row)">
									<div>
										<span class="sort">{{index1 + 1}}</span>
										<span>{{row[column_originConfig[0].name]}}</span>
										<span></span>
									</div>
									<div slot="right-icon" class="van-cell__right-self"
										@click.stop="openButtonArray(index1,$event)" v-if="buttonArray.length > 1">
										<van-icon name="ellipsis" size="20px" color="#9e9e9e"></van-icon>
									</div>
									<div slot="right-icon" v-if="row.checked && isSelect">
										<van-checkbox v-model="row.checked" shape="square" slot="right-icon">
										</van-checkbox>
									</div>
									<div slot="right-icon" v-if="objName == '缺货库存明细查询' && userInfo.S_BranchID != 53">
										<van-checkbox v-model="row.checked" shape="square" slot="right-icon"
											@change="toggleCheckBox(row,index1)"></van-checkbox>
									</div>
								</van-cell>
								<van-cell>
									<van-row>
										<van-col :span="item.van_spanLength"
											v-for="(item,index2) in column_originConfig" v-show="index2 != 0">
											<div class="sub" :class="item.IsBold?'sub-bold':''">
												<span>{{item.label}}：</span>
												<span>{{row[item.name]}}</span>
											</div>
										</van-col>

									</van-row>
								</van-cell>
								<div class="row_bottom_button" v-if="buttonArray.length == 1">
									<van-cell v-for="buttonRow in buttonArray" :value="buttonRow.url" is-link
										@click.stop="showButtonIndex = index1;buttonIntoDetail(buttonRow)"></van-cell>
								</div>

							</div>

						</div>
					</van-list>
				</div>
				<van-loading v-if="showLoading" />
			</div>

			<div class="bottom" v-if="isSelect">
				<div class="bottom-left-label"></div>
				<div class="bottom-right-button">
					<van-button type="primary" block @click="selectArrayConfirm">确定</van-button>
				</div>
			</div>

		</div>

		<van-popup v-model="showSimpleSelect" position="bottom" v-if="formDesign[simpleSelectIndex[0]]">
			<van-picker show-toolbar :columns="columns" :default-index="pickerDefauleIndex"
				:value-key="formDesign[simpleSelectIndex[0]].controls[simpleSelectIndex[1]].controlProperty.select.displayValue"
				@cancel="showSimpleSelect = false" @confirm="simpleSelectChange"></van-picker>
		</van-popup>

		<van-popup v-model="showDatePicker" position="bottom">
			<van-datetime-picker v-model="currentDate" cancel-button-text="清空" type="date" @cancel="clearDatePicker"
				@confirm="confirmDatePicker" />
		</van-popup>

		<van-popup v-model="showSearch" round position="bottom">
			<div v-for="(formRow,index1) in formDesign">
				<div v-for="(formCol,index2) in formRow.controls" v-show="!formCol.baseProperty.isFold">
					<van-field v-if="formCol.baseProperty.controlType=='textbox'"
						:readonly="formCol.baseProperty.isReadOnly" @change="dataChange(formCol)"
						v-model="formData[formCol.baseProperty.controlName]">
						<div slot="label"><span
								:class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
						</div>
					</van-field>
					<van-field v-else-if="formCol.baseProperty.controlType=='number'"
						:label="formCol.baseProperty.labelName" :readonly="formCol.baseProperty.isReadOnly"
						@change="dataChange(formCol)" v-model="formData[formCol.baseProperty.controlName]"
						type="number">
						<div slot="label"><span
								:class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
						</div>
					</van-field>
					<van-cell v-else-if="formCol.baseProperty.controlType=='hidden'"
						:title="formCol.baseProperty.labelName" :value="formData[formCol.baseProperty.controlName]"
						style="display:none;">
					</van-cell>
					<van-cell
						v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 1"
						:value="getsimpleSelectText(index1,index2,formCol)" is-link arrow-direction="down"
						@click="openSimpleSelect(index1,index2,formCol)">
						<div slot="title"><span
								:class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
						</div>
					</van-cell>
					<van-cell
						v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 3"
						:value="formCol.controlProperty.select.actualName || ''" is-link
						@click="openComplexSelect(index1,index2,formCol)">
						<div slot="title"><span
								:class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
						</div>
					</van-cell>
					<van-cell v-else-if="formCol.baseProperty.controlType=='datepicker'"
						:value="formData[formCol.baseProperty.controlName].replace(/T/g,' ')"
						@click="openDatePicker(index1,index2,formCol)">
						<div slot="title"><span
								:class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
						</div>
						<van-icon slot="right-icon" name="../../image/date.png" size="18" style="line-height: inherit;">
						</van-icon>
					</van-cell>
				</div>

			</div>
			<div class="btn-padding">
				<van-button type="primary" block style="border-radius: 0;" @click="searchReport(1)">查询</van-button>
			</div>
		</van-popup>

		<div class="mask" v-show="showButton" @click="showButton = false;"></div>
		<div class="row-button" v-show="showButton">
			<img class="arrow" src="../../image/arrow_white.png" />
			<div>
				<van-cell v-for="row in buttonArray" :value="row.url" @click="buttonIntoDetail(row)"></van-cell>
			</div>

		</div>

		<van-popup v-model="showPopup" :style="{ width: '85%' }" round>
			<div class="c">
				<div class="c-t">调拨数量录入</div>
				<div>
					<van-field type="number" v-model="dbNum" label="调拨数量" placeholder="请输入调拨数量"></van-field>
				</div>
				<div class="btn-padding">
					<van-button color="#83bff6" round :disabled="ifConfirm" :loading="ifConfirm" loading-text="生成中..."
						type="primary" block @click="confirmDBD">生成调拨单</van-button>
				</div>
			</div>
		</van-popup>

	</div>
</body>

<script type="text/javascript">
	var vm, dbIndex = -1;
	apiready = function () {
		//$('.init-full').show();

		api.addEventListener({
			name: 'keyback'
		}, function (ret, err) {
			vm.onClickLeft();
		});

		api.addEventListener({
			name: 'toggleFrameSearch'
		}, function (ret, err) {
			if (api.frameName == ret.value.frameName) {
				vm.showButton = false;
				if (ret.value.frameSearch !== undefined) {
					vm.showSearch = ret.value.frameSearch;
				} else {
					vm.showSearch = !vm.showSearch;
				}


			}
		});

		//复杂下拉选单选选中
		api.addEventListener({
			name: 'selectRow'
		}, function (ret, err) {
			var row = ret.value.row;
			var formCol = vm.formDesign[vm.simpleSelectIndex[0]].controls[vm.simpleSelectIndex[1]];
			vm.formData[formCol.baseProperty.controlName] = row[formCol.controlProperty.select.hiddenValue];
			formCol.controlProperty.select.actualName = row[formCol.controlProperty.select.displayValue];
			vm.selectData[formCol.baseProperty.controlName] = row;
			vm.$set(formCol.controlProperty.select, "sqlDataSource", [row]);
			vm.$set(formCol.controlProperty.select, "originDataSource", [row]);


		})

		//复杂下拉选单选选中
		api.addEventListener({
			name: 'selectArray'
		}, function (ret, err) {

			var array = ret.value.array;
			var formCol = vm.formDesign[vm.simpleSelectIndex[0]].controls[vm.simpleSelectIndex[1]];
			if (formCol.controlProperty.select.chooseType != 1) {
				var idArray = [];
				var textArray = [];
				for (var i in array) {
					idArray.push(array[i][formCol.controlProperty.select.hiddenValue])
					textArray.push(array[i][formCol.controlProperty.select.displayValue])
				}
				vm.formData[formCol.baseProperty.controlName] = idArray.join();
				formCol.controlProperty.select.actualName = textArray.join();
			}
		})

		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				showSearch: false,
				ifConfirm: false,
				listLoading: false,
				listFinished: true,

				userInfo: FLD.getUserInfo(),

				// 额外
				dbNum: '',
				showPopup: false,

				//是否显示简单下拉选
				showSimpleSelect: false,
				//简单下拉选的数组列表
				columns: [],
				//打开下拉选或者日期选择时，所指向的表单列
				simpleSelectIndex: [0, 0],
				//是否显示时间选择器
				showDatePicker: false,
				//打开时间选择器时,选中的时间
				currentDate: new Date(),
				isFrame: api.pageParam.isFrame || false,
				objName: api.pageParam.objName,
				isSelect: api.pageParam.isSelect || false,
				buttonArray: [],
				showButton: false,
				showButtonIndex: -1,
				pickerDefauleIndex: 0, // 单列选择时，picker组件默认选中项索引
				columns: [],
				tableData: [],
				tableData_show: [],
				summaryData: [],
				formDesign: [],
				formData: [],
				searchUpName: '',
				level: 0,
				sql: "",
				report_title: "",
				report_subtitle: "",
				column_originConfig: [],
				column_config: [],
				showSummary: false,
				currentClickRow: {},
				paging: {
					pageSize: 30,
					pageIndex: 0,
					totalCount: 0
				},
				crud: {
					create: [],
					update: [],
					delete: []
				},
				isInitCal: false,
				calDatas: [],
				searchParam: [],
				currentRowData: {}
			},
			created: function () {
				var that = this;
				that.level = api.pageParam.level || 0;


				setTimeout(function () {
					that.showLoading = true;
					tableConfig.initConfig(api.pageParam.objName);
				}, 200)
			},
			methods: {
				getIsSearch() {
					var that = this;
					var x = 0;
					for (var i in that.formDesign) {
						for (var j in that.formDesign[i].controls) {
							if (that.formDesign[i].controls[j].baseProperty.controlType != 'hidden') {
								x = 1;
							}
						}
					}
					return x;
				},
				//简单下拉选根据id显示text
				getsimpleSelectText(index1, index2, formCol) {
					var that = this;
					var sqlDataSource = formCol.controlProperty.select.sqlDataSource;
					var txt = '';
					for (var i in sqlDataSource) {
						if (sqlDataSource[i][that.formDesign[index1].controls[index2].controlProperty.select.hiddenValue] == that.formData[formCol.baseProperty.controlName]) {
							txt = sqlDataSource[i][that.formDesign[index1].controls[index2].controlProperty.select.displayValue];
						}
					}
					return txt || ' ';
				},
				//打开简单下拉选
				openSimpleSelect(index1, index2, formCol) {
					var that = this;
					that.simpleSelectIndex = [index1, index2]
					that.columns = formCol.controlProperty.select.sqlDataSource;
					for (var i in that.columns) {
						if (that.columns[i][that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]].controlProperty.select.displayValue] === null) {
							that.columns[i][that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]].controlProperty.select.displayValue] = '';
						}
					}
					let today = FLD.dateFormat(new Date(), 'Y-MM');
					let findInd = that.columns.findIndex(item => item.date == today);

					that.pickerDefauleIndex = findInd != -1 ? findInd : 0;

					that.showSimpleSelect = true;
				},
				//简单下拉选选中
				simpleSelectChange(value, index) {
					var that = this;
					var formCol = that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]];
					that.formData[formCol.baseProperty.controlName] = formCol.controlProperty.select.sqlDataSource[index][formCol.controlProperty.select.hiddenValue];
					// formCol.controlProperty.select.actualName = value[formCol.controlProperty.select.displayValue];
					that.showSimpleSelect = false;

					that.selectDataChange(formCol);
				},
				//打开复杂下拉选
				openComplexSelect(index1, index2, formCol) {
					var that = this;
					that.simpleSelectIndex = [index1, index2];
					var filter = formCol.controlProperty.select.formSQL;
					for (var key in that.formData) {
						var value = "'" + that.formData[key] + "'";
						filter = eval("filter.replace(/" + "@" + key + "/g,value)")
					}

					api.openWin({
						name: '复杂筛选' + formCol.controlProperty.url,
						url: 'formConfigScreen.html',
						reload: true,
						slidBackEnabled: false,
						pageParam: {
							filter: filter,
							screenName: formCol.controlProperty.select.url,
							allowClear: true,
							type: formCol.controlProperty.select.chooseType,
							isDetail: false,
							objName: that.objName
						}
					})
				},
				//打开日期选择器
				openDatePicker(index1, index2, formCol) {
					var that = this;
					if (formCol.baseProperty.isReadOnly) {
						return false;
					}
					that.simpleSelectIndex = [index1, index2];
					that.currentDate = new Date(that.formData[formCol.baseProperty.controlName]);
					that.showDatePicker = true;
				},
				//清空所选日期
				clearDatePicker() {
					var that = this;
					var formCol = that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]];
					that.formData[formCol.baseProperty.controlName] = '';
					that.showDatePicker = false;
					that.dataChange(formCol);
				},
				//确认当前所选日期
				confirmDatePicker(value) {
					var that = this;
					var formCol = that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]];
					that.formData[formCol.baseProperty.controlName] = FLD.getFormatDate(value).split(' ')[0];
					that.showDatePicker = false;
					that.dataChange(formCol);
				},
				listOnLoad() {
					var that = this;
					setTimeout(function () {
						that.listLoading = false;
						if (that.tableData.length > that.tableData_show.length) {
							var show_length = that.tableData_show.length;
							var tableData_show = []
							for (var i = show_length; i < show_length + 30; i++) {
								if (that.tableData[i]) {
									tableData_show.push(JSON.parse(JSON.stringify(that.tableData[i])));
								}
							}
							that.tableData_show = that.tableData_show.concat(tableData_show)
						} else {
							that.listFinished = true;
						}
					}, 200)


				},
				setTotalCol() {
					var that = this;
					if (that.summaryData.length <= 3) {
						return that.summaryData.length
					} else {
						if (that.summaryData.length == 4) {
							return 2;
						} else {
							return 3;
						}
					}
				},
				openButtonArray(index, e) {
					var that = this;
					that.showButtonIndex = index;
					var top = $(e.target).closest('.row').offset().top - $('.content').closest('.row').scrollTop();
					$('.row-button').css({
						'top': top + 40 + 'px'
					})
					that.showButton = true;
				},
				getIsLink(row) {
					var that = this;
					if (!that.buttonArray.length) {
						if (row.IsEnd === 0) {
							return true;
						} else if (row.IsEnd === 1) {
							return false;
						} else if (that.column_originConfig[0].url) {
							return true;
						} else {
							return false;
						}
					} else {
						return false;
					}

				},
				selectArrayConfirm() {
					var that = this;
					var checkArray = [];
					for (var i in that.tableData_show) {
						if (that.tableData_show[i].checked) {
							checkArray.push(that.tableData_show[i]);

						}
					}
					if (checkArray.length) {
						api.sendEvent({
							name: 'selectSuccess',
							extra: {
								array: checkArray
							}
						});
						api.closeToWin({
							name: 'tripList'
						});
					} else {
						layer.open({
							content: '请至少选择一家客户!',
							skin: 'msg',
							time: 2
						});
					}
				},
				toggleCheckBox(row, index) {
					var that = this;
					for (var i in that.tableData_show) {
						if (i != index) {
							that.$set(that.tableData_show[i], 'checked', false);
						}
					}
					if (row.checked) {
						that.showPopup = true;
						dbIndex = index;
					}
				},
				confirmDBD() {
					var that = this;
					if (!that.dbNum) {
						layer.open({
							content: '请输入调拨数量',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					var obj = {
						S_YStockID: that.tableData_show[dbIndex].StockID,
						S_BNum: that.dbNum,
						S_NStockID: that.tableData_show[dbIndex].Y_StockID,
						S_ProductID: that.tableData_show[dbIndex].ProductID
					}
					FLD.ajax('APP_QHBBSCFDBN', obj, function (res) {
						if (res.ds[0].status == 200) {
							layer.open({
								content: '调拨单生成成功',
								skin: 'msg',
								time: 2
							});
							that.showPopup = false;
						} else {
							layer.open({
								content: res.ds[0].msg,
								skin: 'msg',
								time: 2
							});
						}
					})
				},
				buttonIntoDetail(row) {
					var that = this;
					that.showButton = false;
					reportToSelfPageConfig.intoSelf(that.tableData_show[that.showButtonIndex], row, function () {
						api.openWin({
							name: row.url + '_0',
							url: 'formConfigReport.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: {
								objName: row.url,
								formData: that.tableData_show[that.showButtonIndex]
							}
						})
					})
				},
				intoDetail(row, index) {

					var that = this;
					if (that.isSelect) {
						if (typeof row.checked === 'undefined') {
							this.$set(row, 'checked', true);
						} else {
							row.checked = !row.checked;
						}
						return false;
					}
					if ((row.IsEnd === 1 || row.IsEnd === undefined) && !that.column_originConfig[index].url) {
						return false;
					}
					that.clearHistoryWin();
					var formData = JSON.parse(JSON.stringify(that.formData));
					formData[that.searchUpName] = row[that.column_originConfig[index].UpId];

					if (that.column_originConfig[index].url) {
						reportToSelfPageConfig.intoSelf(row, that.column_originConfig[index], function () {
							api.openWin({
								name: that.column_originConfig[index].url + '_0',
								url: 'formConfigReport.html',
								reload: true,
								slidBackEnabled: false,
								pageParam: {
									objName: that.column_originConfig[index].url,
									formData: row
								}
							})
						})


					} else {
						var new_level = that.level + 1;
						api.openWin({
							name: that.objName + '_' + new_level,
							url: 'formConfigReport.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: {
								objName: that.objName,
								level: new_level,
								formData: formData
							}
						})
					}

				},


				//验证必填项
				valitedRequired() {
					var resultObj = { status: 200, msg: "" };
					for (var i = 0; i < vm.formDesign.length; i++) {
						for (var j = 0; j < vm.formDesign[i].controls.length; j++) {
							if (vm.formDesign[i].controls[j].baseProperty.isRequired) {
								if (vm.formData[vm.formDesign[i].controls[j].baseProperty.controlName] == "" || vm.formData[vm.formDesign[i].controls[j].baseProperty.controlName] == null) {
									resultObj = {
										status: 500,
										msg: vm.formDesign[i].controls[j].baseProperty.labelName + "字段不能为空!"
									};
								}
							}
						}
					}
					return resultObj;
				},
				//报表查询
				searchReport(s) {
					var that = this;
					//验证必填项
					vm.showSearch = false;
					var valitedResult = vm.valitedRequired();
					if (valitedResult.status == 500) {
						layer.alert(valitedResult.msg);
						return;
					} else {
						vm.isInitCal = false;
						if (s && !that.isFrame) {
							var winNameArray = api.winName.split('_');
							var winNum = parseInt(winNameArray[1])
							if (winNum != 0) {
								var destroyArray = [];
								for (var i = 0; i <= winNum; i++) {
									if (i != 0) {
										destroyArray.push(winNameArray[0] + '_' + i);
									}
								}
								var formData = JSON.parse(JSON.stringify(that.formData));
								formData[that.searchUpName] = 0;
								api.closeWin({
									name: winNameArray[0] + '_0'
								})
								api.openWin({
									name: winNameArray[0] + '_0',
									url: 'formConfigReport.html',
									reload: true,
									slidBackEnabled: false,
									pageParam: {
										objName: winNameArray[0],
										formData: formData,
										destroyArray: destroyArray
									}
								})
							}

						}
						var searchParam = [];
						var x = 0;
						for (var key in vm.formData) {
							if (key == 'P_UserID') {
								x = 1;
							}
							searchParam.push({
								Key: key,
								Value: vm.formData[key]
							})
						}
						if (x == 0) {
							searchParam.push({
								Key: 'P_UserID',
								Value: FLD.getUserInfo().UserID
							})
						}

						$.ajax({
							url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
							async: true,
							data: {
								programId: localStorage.getItem("programId"),
								sql: vm.sql,
								sqlParam: searchParam
							},
							type: "post",
							timeout: 1000 * 60 * 5, //超时时间：5分钟
							dataType: 'json',
							success: function (data) {
								vm.showLoading = false;
								vm.listFinished = false;
								if (data.status == 200) {
									//列配置
									if (data.data.ds != undefined && data.data.ds.length > 0) {
										var column_originConfig = data.data.ds.sort(function (a, b) {
											return a.RowNo - b.RowNo;
										});
										var repeatColumn_originConfig = function (x) {
											if (x == column_originConfig.length + 1) {
												return false;
											}
											var rowLengthArray = column_originConfig.filter(function (row) {
												return row.RowNo == x;
											})
											for (var i in rowLengthArray) {
												rowLengthArray[i].van_spanLength = 24 / rowLengthArray.length;
											}
											x++;
											repeatColumn_originConfig(x);
										}
										repeatColumn_originConfig(1);
										vm.column_originConfig = column_originConfig;
										vm.buttonArray = [];
										for (var i in vm.column_originConfig) {

											if (i != 0 && vm.column_originConfig[i].url) {
												vm.buttonArray.push(vm.column_originConfig[i]);
											}
										}
									}
									//数据源配置
									if (data.data.ds1 != undefined && data.data.ds1.length > 0) {
										vm.tableData = data.data.ds1;
										vm.tableData_show = [];
										for (var i = 0; i < 30; i++) {
											if (vm.tableData[i]) {
												vm.tableData_show.push(JSON.parse(JSON.stringify(vm.tableData[i])))
											}
										}
										var colProperty = {
											columns: []
										};
										if (data.data.ds1.length > 0) {
											var repeatColumn = function (array) {
												for (var i in array) {
													colProperty.columns.push({
														property: array[i].name,
														label: array[i].label
													});
												}
											}
											repeatColumn(vm.column_originConfig)

											vm.summaryData = vm.getSummaries();
										}
									}
									else {
										vm.tableData = [];
										vm.tableData_show = [];
										vm.summaryData = vm.getSummaries();
									}

								}
							}
						});
					}
				},
				cellClassName(row) {
					var column = row.column;
					var currentColumnConfig = vm.column_originConfig.filter(function (item) { return item.label == column.label });
					if (currentColumnConfig.length > 0) {
						if (currentColumnConfig[0].url) {
							return "navigateUrl";
						}
					}
					return "";
				},
				cellClick(row, column, cell, event) {
					var currentColumnConfig = vm.column_originConfig.filter(function (item) { return item.label == column.label });
					if (currentColumnConfig.length > 0) {
						var searchParam = [];
						for (var key in vm.formData) {
							searchParam.push({
								Key: key,
								Value: vm.formData[key]
							})
						}
						vm.searchParam = searchParam;
						vm.currentRowData = JSON.parse(JSON.stringify(row))
						if (currentColumnConfig[0].url) {
							if (currentColumnConfig[0].url.toLowerCase().indexOf('report') >= 0) {
								layer.open({
									type: 2,
									title: '明细子报表',
									anim: 5,
									maxmin: true,
									shadeClose: false,
									area: ['100%', '100%'],
									content: currentColumnConfig[0].url + "&subReport=1",
									cancel: function () {
									}
								});
							}
							else if (currentColumnConfig[0].url == "formdetail") {
								//具体单据详情字段，列中必须配有主键名+主键值字段formName+ keyName+keyValue
								var url = "/FormDetail/Detail?objName=" + vm.currentRowData["formName"] + "&keyName=" + vm.currentRowData["keyName"] + "&keyValue=" + vm.currentRowData["keyValue"];
								parent.layer.open({
									type: 2,
									title: '明细子报表',
									anim: 5,
									maxmin: true,
									shadeClose: false,
									area: ['100%', '100%'],
									content: url,
									cancel: function () {
									}
								});
							}
						}
					}
				},
				//清除表单数据
				clearFormData(control) {
					vm.formData[control.baseProperty.controlName] = "";
					control.controlProperty.select.actualName = "";
				},
				getSubColumn(allData, parentName) {
					var subColumn = allData.filter(function (item) { return item.parentName == parentName });
					for (var j = 0; j < subColumn.length; j++) {
						if (subColumn[j].total != "") {
							vm.showSummary = true;
						}
						subColumn[j].subColumn = vm.getSubColumn(allData, subColumn[j].name);
					}
					return subColumn;
				},
				getSummaries() {
					if (vm.isInitCal) {
						return vm.calDatas;
					}
					var totalData = [];
					for (var i = 0; i < vm.column_originConfig.length; i++) {
						var subTotalData = "";
						var current_Column = vm.column_originConfig[i];
						if (current_Column) {
							if (current_Column.total != "") {
								if (current_Column.total.indexOf('sum') >= 0) {
									//保留位数
									var fixNum = 0;
									if (current_Column.total.indexOf(',') >= 0) {
										fixNum = parseInt(current_Column.total.split(',')[1]);
									}
									var totalNum = 0;
									for (var j = 0; j < vm.tableData.length; j++) {
										var currentNum = parseFloat(vm.tableData[j][current_Column.name]);
										if (isNaN(currentNum)) {
											currentNum = 0;
										}
										totalNum += currentNum;
									}

									subTotalData = totalNum.toFixed(fixNum);
								}
								else if (current_Column.total.indexOf('avg') >= 0) {
									//保留位数
									var fixNum = 0;
									if (current_Column.total.indexOf(',') >= 0) {
										fixNum = parseInt(current_Column.total.split(',')[1]);
									}
									var totalNum = 0;
									for (var j = 0; j < vm.tableData.length; j++) {
										var currentNum = parseFloat(vm.tableData[j][current_Column.name]);
										if (isNaN(currentNum)) {
											currentNum = 0;
										}
										totalNum += currentNum;
									}
									if (vm.tableData.length > 0) {
										subTotalData = (totalNum / vm.tableData.length).toFixed(fixNum);
									}
									else {
										subTotalData = "0";
									}
								}
								totalData.push({
									label: vm.column_originConfig[i].label,
									value: subTotalData
								});
							}
						}


					}
					vm.calDatas = totalData;
					vm.isInitCal = true;
					return totalData;
				},
				showSelectTreeWindow(colProperty, selValue, controlName, currentControl) {
					var currentLayerNo = new Date().getTime();
					var url = colProperty.select.url;
					if (url.indexOf('?') < 0) {
						url = url + "?t=1"
					}
					url += "&layerNo=" + currentLayerNo;
					var selObj = colProperty.select.sqlDataSource.filter(function (item) { return item[colProperty.select.hiddenValue] == selValue });
					var selName = "";
					if (selObj.length > 0) {
						selName = selObj[0][colProperty.select.displayValue]
					}
					url += "&selectName=" + selName;
					url += "&selectValue=" + selValue;
					url += "&selectArea=1";
					url += "&selectKeyName=" + colProperty.select.hiddenValue;
					url += "&selectKeyValue=" + colProperty.select.displayValue;
					url += "&chooseType=" + colProperty.select.chooseType;
					top.window[currentLayerNo] = window;
					var layerIndex = top.layer.open({
						type: 2,
						title: '表单数据源',
						anim: 5,
						maxmin: true,
						shadeClose: false,
						area: ['80%', '80%'],
						content: url,
						cancel: function () {
						}
					});
					top.window[currentLayerNo + "_index"] = layerIndex;
					vm.currentControlName = controlName;
					vm.currentControl = currentControl;

					//通过localstage传递所需要的参数
					var treeSQL = '', formSQL = '';
					if (colProperty.select.treeSQL) {
						treeSQL = colProperty.select.treeSQL;
					}
					if (colProperty.select.formSQL) {
						formSQL = colProperty.select.formSQL;
					}
					if (url.toLowerCase().indexOf('tree') >= 0 && treeSQL != '') {
						localStorage.setItem(currentLayerNo + "_treeSQL", treeSQL);
						localStorage.setItem(currentLayerNo + "_treeSQLData", JSON.stringify(vm.formData));
					}
					if (formSQL != '') {
						localStorage.setItem(currentLayerNo + "_formSQL", formSQL);
						localStorage.setItem(currentLayerNo + "_formSQLData", JSON.stringify(vm.formData));
					}
				},
				//提交选中树型窗口
				submitSelectTreeWindow(selectKeyValue) {
					vm.isInitPage = false;
					vm.formData[vm.currentControlName] = selectKeyValue;
					var valueList = [];
					if (vm.formData[vm.currentControlName] != undefined && vm.formData[vm.currentControlName] != "") {
						for (var i = 0; i < vm.formData[vm.currentControlName].toString().split(',').length; i++) {
							valueList.push("'" + vm.formData[vm.currentControlName].toString().split(',')[i] + "'")
						}
					}
					var sql = "select * from (" + vm.currentControl.controlProperty.select.dataSource + ")t";
					if (valueList.length > 0) {
						sql += " where " + vm.currentControl.controlProperty.select.hiddenValue + " in (" + valueList.join(',') + ") ";
						$.ajax({
							url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
							async: false,
							data: {
								programId: localStorage.getItem("programId"),
								sql: sql
							},
							type: "post",
							dataType: 'json',
							success: function (data) {
								if (data.status == 200) {
									vm.$set(vm.currentControl.controlProperty.select, "sqlDataSource", data.data.ds);
									vm.$set(vm.currentControl.controlProperty.select, "originDataSource", data.data.ds);
									//绑定固定值
									vm.$set(vm.currentControl.controlProperty.select, "actualName", "");
									vm.$set(vm.currentControl.controlProperty.select, "actualName", data.data.ds.filter(function (item) { return item[vm.currentControl.controlProperty.select.displayValue] }).join(','));
								}
							}
						});
					}
					else {
						vm.$set(vm.currentControl.controlProperty.select, "actualName", "");
					}
				},
				//三个小点提交选中事件
				selectTableSubmit($event, col) {
					if (window.event.keyCode == 13) {
						vm.currentControlName = col.baseProperty.controlName;
						vm.currentControl = col;
						window.event.preventDefault();
						var searchKey = $($event.target).val();
						var searchParam = [];
						for (var key in vm.currentClickRow) {
							searchParam.push({
								Key: key,
								Value: vm.currentClickRow[key]
							})
						}
						if (col.controlProperty.select.filterSQL) {
							$.post("http://" + FLD.serverIP + "/SQLData/QueryFilterSQL", {
								programId: localStorage.getItem("programId"),
								sql: col.controlProperty.select.dataSource + " where " + col.controlProperty.select.filterSQL,
								moduleUrl: col.controlProperty.select.url,
								searchKey: searchKey,
								sqlParam: searchParam
							}, function (data) {
								$($event.target).hide();
								$($event.target).prev().children("input").css({
									opacity: 1
								})
								//单条数据
								if (data.status == 200) {
									var selectKeyValue = data.data[0][col.controlProperty.select.hiddenValue];

									if (selectKeyValue == "") {
										vm.formData[vm.currentControlName] = null;
										vm.$set(col.controlProperty.select, "actualName", "");
									}
									else {
										vm.formData[col.baseProperty.controlName] = selectKeyValue;
										vm.$set(col.controlProperty.select, "actualName", data.data[0][col.controlProperty.select.displayValue]);
										vm.$set(col.controlProperty.select, "sqlDataSource", data.data);
									}

									if (col.controlProperty.select.change != "") {
										vm.selectChange(col);
									}
									if (col.baseProperty.controlCallBack) {
										var script = col.baseProperty.controlCallBack.replace(/\['/g, "vm.formData['");
										script = script.replace(/\["/g, "vm.formData[\"");
										eval(script);
										vm.refreshInitActualName();
									}
								}
								else if (data.status == 201) {
									var currentLayerNo = new Date().getTime();
									var dbDetail = col.controlProperty.select;
									var url = dbDetail.url;
									if (url.indexOf('?') < 0) {
										url = url + "?t=1"
									}
									url += "&layerNo=" + currentLayerNo;
									var selValue = "";
									var selName = "";
									url += "&selectName=" + selName;
									url += "&selectValue=" + selValue;
									url += "&selectArea=1";
									url += "&selectKeyName=" + dbDetail.hiddenValue;
									url += "&selectKeyValue=" + dbDetail.displayValue;
									url += "&chooseType=" + dbDetail.chooseType;
									top.window[currentLayerNo] = window;

									var layerIndex = top.layer.open({
										type: 2,
										title: '表单数据源',
										anim: 5,
										maxmin: true,
										shadeClose: false,
										area: ['80%', '80%'],
										content: url,
										cancel: function () {
										}
									});
									//通过localstage传递所需要的参数
									var treeSQL = '', filterSQL = '';
									if (dbDetail.treeSQL) {
										treeSQL = dbDetail.treeSQL;
									}
									if (dbDetail.filterSQL) {
										filterSQL = dbDetail.filterSQL;
										String.prototype.replaceAll = function (s1, s2) {
											return this.replace(new RegExp(s1, "gm"), s2);
										}
										filterSQL = filterSQL.replaceAll("@searchKey", "'%'+'" + searchKey + "'+'%'");

									}
									localStorage.setItem(currentLayerNo + "_treeSQLData", JSON.stringify(col));
									if (url.toLowerCase().indexOf('tree') >= 0 && treeSQL != '') {
										localStorage.setItem(currentLayerNo + "_treeSQL", treeSQL);
									}
									if (filterSQL != '') {
										localStorage.setItem(currentLayerNo + "_filterSQL", filterSQL);
										localStorage.setItem(currentLayerNo + "_filterSQLData", JSON.stringify(col));
									}
									top.window[currentLayerNo + "_index"] = layerIndex;
								}
								else {
									layer.msg(data.msg);
								}
							}, "json");
						}
						//vm.currentClickCol
						//vm.currentClickRow
					}
				},
				//三个小点显示事件
				showSelectTableSubmit(obj) {
					debugger;
					var domCurrent = $(obj).parent().next();
					domCurrent.val($(obj).val());
					if ($(obj).css("background")) {
						domCurrent.css({
							background: $(obj).css("background")
						});
					}
					$(obj).css({
						opacity: 0
					});
					domCurrent.show();
					domCurrent.focus();
					domCurrent.unbind("blur");
					domCurrent.blur(function () {
						domCurrent.hide();
						$(obj).css({
							opacity: 1
						});
					});
				},
				//系统默认常量时间
				getSYDefaultValue(funcName) {
					if (funcName == "getdate()") {
						var date = new Date();
						var seperator1 = "-";
						var seperator2 = ":";
						var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
						var strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
						var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
							+ " " + date.getHours() + seperator2 + date.getMinutes()
							+ seperator2 + date.getSeconds();
						return currentdate;
					}
					else {
						return funcName;
					}
				},
				clearHistoryWin() {
					var destroyArray = api.pageParam.destroyArray || [];
					for (var i in destroyArray) {
						api.closeWin({
							name: destroyArray[i]
						})

					}
				},
				onClickLeft() {
					var that = this;
					that.clearHistoryWin();
					api.closeWin();
				}
			}
		})


		var tableConfig = {
			//设置配置
			set: function (options) {
				vm.sql = options.sql;
				if (api.pageParam.formData) {
					vm.formData = api.pageParam.formData;
				} else {
					vm.formData = {};
				}
				var rowDesignFormData = [];
				for (var i = 0; i < options.formDesign.length; i++) {
					//增加查询默认值
					if (!(options.formDesign[i].baseProperty.controlName in vm.formData)) {
						if (options.formDesign[i].baseProperty.controlType == "hidden") {
							vm.$set(vm.formData, options.formDesign[i].baseProperty.controlName, 0);
						} else {
							vm.$set(vm.formData, options.formDesign[i].baseProperty.controlName, vm.getSYDefaultValue(options.formDesign[i].baseProperty.defaultValue));
						}

					}


					var rowId = options.formDesign[i].baseProperty.rowId;
					if (options.formDesign[i].baseProperty.controlType == "select") {
						//下拉框数据加载
						if (options.formDesign[i].controlProperty.select.type < 3) {
							var sql = options.formDesign[i].controlProperty.select.dataSource;
							$.ajax({
								url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
								async: false,
								data: {
									programId: localStorage.getItem("programId"),
									sql: sql
								},
								type: "post",
								dataType: 'json',
								success: function (data) {
									if (data.status == 200) {
										options.formDesign[i].controlProperty.select.sqlDataSource = data.data.ds;
										options.formDesign[i].controlProperty.select.originDataSource = data.data.ds;
										//判断隐藏值类型和当前赋值类型是否一致
										if (data.data.ds.length > 0 && vm.formData[options.formDesign[i].baseProperty.controlName]) {
											var dataType = typeof (data.data.ds[0][options.formDesign[i].controlProperty.select.hiddenValue]);
											if (dataType != typeof (vm.formData[options.formDesign[i].baseProperty.controlName])) {
												if (dataType == "int" || dataType == "number") {
													vm.formData[options.formDesign[i].baseProperty.controlName] = parseInt(vm.formData[options.formDesign[i].baseProperty.controlName]);
												}
												else if (dataType == "boolean") {
													vm.formData[options.formDesign[i].baseProperty.controlName] = Boolean(parseInt(vm.formData[options.formDesign[i].baseProperty.controlName]));
												}
											}
											else {
												vm.formData[options.formDesign[i].baseProperty.controlName] = vm.formData[options.formDesign[i].baseProperty.controlName];
											}
										}
									}
								}
							});
						}
						else if (options.formDesign[i].controlProperty.select.type == 3) {
							var valueList = [];
							if (vm.formData[options.formDesign[i].baseProperty.controlName] != undefined && vm.formData[options.formDesign[i].baseProperty.controlName] != "") {
								valueList.push("'" + vm.formData[options.formDesign[i].baseProperty.controlName] + "'");
							}
							var sql = "select * from (" + options.formDesign[i].controlProperty.select.dataSource + ")t";
							if (valueList.length > 0) {
								sql += " where " + options.formDesign[i].controlProperty.select.hiddenValue + " in (" + valueList.join(',') + ") ";
								$.ajax({
									url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
									async: false,
									data: {
										programId: localStorage.getItem("programId"),
										sql: sql
									},
									type: "post",
									dataType: 'json',
									success: function (data) {
										if (data.status == 200) {
											vm.$set(options.formDesign[i].controlProperty.select, "sqlDataSource", data.data.ds);
											vm.$set(options.formDesign[i].controlProperty.select, "originDataSource", data.data.ds);
											//绑定固定值
											vm.$set(options.formDesign[i].controlProperty.select, "actualName", "");
											var actualList = data.data.ds.filter(function (item) { return item[options.formDesign[i].controlProperty.select.hiddenValue] == vm.formData[options.formDesign[i].baseProperty.controlName] });
											if (actualList.length > 0) {
												vm.$set(options.formDesign[i].controlProperty.select, "actualName", actualList[0][options.formDesign[i].controlProperty.select.displayValue]);

											}
										}
									}
								});
							}
							else {
								vm.$set(options.formDesign[i].controlProperty.select, "sqlDataSource", []);
								vm.$set(options.formDesign[i].controlProperty.select, "originDataSource", []);
								vm.$set(options.formDesign[i].controlProperty.select, "actualName", "");
							}
						}
					} else {
						if (options.formDesign[i].baseProperty.controlType == "hidden") {
							vm.searchUpName = options.formDesign[i].baseProperty.controlName;
							// if (!api.pageParam.formData) {
							// 	vm.$set(vm.formData, options.formDesign[i].baseProperty.controlName, 0);
							// }
						}
					}

					var designDataList = rowDesignFormData.filter(function (item) { return item.rowId == rowId; });
					if (designDataList.length > 0) {
						designDataList[0].controls.push(options.formDesign[i]);
					}
					else {
						rowDesignFormData.push({
							rowId: rowId,
							controls: [options.formDesign[i]]
						});
					}
				}
				vm.formDesign = rowDesignFormData;
				// setTimeout(function () {
				// 	vm.controlInit();
				// }, 300);
				vm.searchReport();


			},
			//初始化配置
			initConfig: function (objName) {

				if (objName == undefined) {
					return;
				}
				$.post("http://" + FLD.serverIP + "/APPReportList/GetDataByName", {
					programId: localStorage.getItem("programId"),
					objName: objName
				}, function (data) {
					var formDesign = [];
					if (data.data.ds[0]["searchDesignConfig"] && data.data.ds[0]["searchDesignConfig"] != 'null') {
						formDesign = JSON.parse(data.data.ds[0]["searchDesignConfig"])
					}
					tableConfig.set({
						sql: data.data.ds[0]["sql"],
						formDesign: formDesign
					});
				}, "json");
			}
		}

	};
</script>

</html>